/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : lowpass_filter.c
  * @brief          : lowpass filter 
  * @author         : Yan Yuanbin
  * @date           : 2023/04/27
  * @version        : v1.0
  ******************************************************************************
  * @attention      : To be perfected
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef LOWPASS_FILTER_H
#define LOWPASS_FILTER_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "config.h"

/* Exported types ------------------------------------------------------------*/
/**
 * @brief typedef structure that contains the information  for the first order lowpass filter.
 */
typedef struct
{
    bool  Initialized;     /*!< init flag */
    float Input;          /*!< input value */
    float Output;         /*!< output value */
	  float Last_Output;
    float Alpha;          /*!< filter coefficient */
    float Frame_Period;   /*!< frame perood */
}LowPassFilter1p_Info_TypeDef;


typedef struct
{
    bool  Initialized;     /*!< init flag */
    float Input;          /*!< input value */
    float Output;         /*!< output value */
	  float Last_Input;
    float Alpha;          /*!< filter coefficient */
    float Frame_Period;   /*!< frame perood */
}HighPassFilter1p_Info_TypeDef;





/**
 * @brief typedef structure that contains the information for the second order lowpass filter.
 */
typedef struct 
{
    bool Initialized;  /*!< init flag */
    float input;       /*!< input value */
    float output[3];   /*!< output value */
    float alpha[3];    /*!< filter coefficient */
}LowPassFilter2p_Info_TypeDef;

typedef struct
{
   float Input; //Input signal
   float r; //Filter coefficient
   float h; //frame perood  h
	 float Output; //output value
   float d_Output; //derivative output value
   float Err;
	 float fh;
}Tracking_Differentiator_Info_TypeDef;	
/* Exported functions prototypes ---------------------------------------------*/
extern void Tracking_Differentiator_Init(Tracking_Differentiator_Info_TypeDef *TD,float r,float h);

extern void Tracking_Differentiator_Update(Tracking_Differentiator_Info_TypeDef *TD,float Input);

/**
  * @brief Initializes the first order lowpass filter according to the specified parameters in the
  *         LowPassFilter1p_Info_TypeDef.
  */
extern void LowPassFilter1p_Init(LowPassFilter1p_Info_TypeDef *LPF,float Alpha,float Frame_Period);
/**
  * @brief Update the first order lowpass filter according to the specified parameters in the
  *         LowPassFilter1p_Info_TypeDef.
  */
extern float LowPassFilter1p_Update(LowPassFilter1p_Info_TypeDef *LPF,float Input);
/**
  * @brief Initializes the Second order lowpass filter according to the specified parameters in the
  *         LowPassFilter2p_Info_TypeDef.
  */

extern float HighPassFilter1p_Update(HighPassFilter1p_Info_TypeDef *LPF,float Input);


extern void HighPassFilter1p_Init(HighPassFilter1p_Info_TypeDef *LPF,float Alpha,float Frame_Period);




extern void LowPassFilter2p_Init(LowPassFilter2p_Info_TypeDef *lpf,float alpha[3]);
/**
  * @brief Update the Second order lowpass filter according to the specified parameters in the
  *         LowPassFilter2p_Info_TypeDef.
  */
extern float LowPassFilter2p_Update(LowPassFilter2p_Info_TypeDef *lpf,float input);


extern float sign(float input);
#endif //LOWPASS_FILTER_H
